package cn.cqs.redisitem.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @discription :获取bean实例
 * @author: cqs
 * @date: 2020-09-11 15:25
 */
//@Component
public class ApplicationContextUtil implements ApplicationContextAware {
    // IOC容器
    private static ApplicationContext context;

    /**
     * 功能描述 : 将IOC容器回调给我们，我们将它缓存起来
     *
     * @param applicationContext:
     * @return void
     * @author cqs
     * @date 2020/9/11
     */

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;

    }
    /**
     * 功能描述 :从IOC容器中获取组件（bean)
     * @author cqs
     * @date 2020/9/11
     * @param beanName:
     * @return java.lang.Object
     */

    public Object getbean(String beanName) {
        return context.getBean(beanName);
    }
}
